<?php

class Adb
{

  private $db;

  protected $name;

  protected $profile;

  protected function __construct($name, $profile = 'default')
  {
    $this->name = $name;
    $this->profile = $profile;
  }

  public function getName()
  {
    return $this->name;
  }

  /**
   *
   * @return IDataAccessObject
   */
  protected function db()
  {
    if (empty($this->db)) {
      $this->db = DB::getInstance($this->profile)->db();
      $this->db->loadModule('Manager');
      $this->db->loadModule('Reverse');
    }

    return $this->db;
  }

  /**
   *
   * @return MDB2_Driver_Manager_Common
   */
  protected function manager()
  {
    return $this->db()->manager;
  }

  /**
   *
   * @return MDB2_Driver_Reverse_Common
   */
  protected function reverse()
  {
    return $this->db()->reverse;
  }

}
